<template>
	<view class="pay">
		<view class="payorder">
			<view class="payNumber">
				订单号:{{outTradeNo}}
			</view>
			<view class="payPrice">
				<text>¥</text>{{totalAmount}}
			</view>
			<view class="payTime">
				<!-- 最迟支付时间:{{payinfo.end_time}} -->
			</view>
		</view>
		<view class="payType">
			<view class="payTypeTitle">
				请选择支付方式
			</view>
			<radio-group @change="radioChange">
				<view class="payTypeItem">
					<view class="payTypeItemLeft">
						<image src="../../static/images/alipay.png" class="payicon"></image>支付宝支付
					</view>
					<radio color="#01c2fa" value="1" checked=""></radio>
				</view>
				<view class="payTypeItem">
					<view class="payTypeItemLeft">
						<image src="../../static/images/wxpay.png" class="payicon"></image>微信支付
					</view>
					<radio color="#01c2fa" value="2"></radio>
				</view>
			</radio-group>

		</view>
		<view class="payButton" @click="pay">
			确定支付
		</view>
		<!-- 添加支付表单区域 -->
		<div id="divform"></div>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				paytype: 1,
				payForm: '', //初始化支付表单
				totalAmount: 0, //初始化总支付金额
				outTradeNo: '2012121909021', //初始化主订单号
			}
		},
		onLoad(option) {
			console.log(option);
			let {
				outTradeNo,
				countmoney
			} = option
			this.outTradeNo = outTradeNo;
			this.totalAmount = countmoney;

		},
		onShow() {

		},
		methods: {
			// 生成订单
			async pay() {
				let res = await this.$http({
					url: '/alipay',
					method: 'post',
					header: {
						authorization: uni.getStorageSync('userInfo').token
					},
					data: {
						outTradeNo: this.outTradeNo,
						totalAmount: this.totalAmount,
						type: 1
					}
				})
				console.log(res);
				// 提交成功
				if (res.data.code == 200) {
					// 提交支付返回一个form表单  让表单自动提交
					let divform = document.getElementById('divform');
					// 解析表单
					divform.innerHTML = res.data.list;
					document.forms[0].submit(); //自动提交表单
				}
			},
			// 切换支付方式
			radioChange() {}
		}

	}
</script>

<style>
	/* 引入样式 */
	/* @import '@/static/css/pay.css'; */
	.payicon {
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}

	.payButton {
		height: 80rpx;
		width: 624rpx;
		position: fixed;
		bottom: 120rpx;
		background: #0bbaef;
		left: 50%;
		margin-left: -312rpx;
		text-align: center;
		line-height: 80rpx;
		color: #fff;
		font-size: 28rpx;
		border-radius: 80rpx;
	}


	.payType {
		width: 650rpx;
		margin: 58rpx auto 0;
	}

	.payType .payTypeTitle {
		font-size: 28rpx;
		line-height: 55rpx;
	}

	.payType .payTypeItem {
		display: flex;
		justify-content: space-between;
		height: 76rpx;
		align-items: center;
	}

	.payTypeItemLeft {
		font-size: 28rpx;
		display: flex;
		align-items: center;
	}

	.payType .payTypeItem i {
		font-size: 32rpx;
		margin-right: 20rpx;
		display: block;
	}

	.payType .payTypeItem radio {
		transform: scale(0.7);
	}

	/* switch */


	.payNumber {
		font-size: 24rpx;
		color: #999;
		text-align: center;
		padding-top: 54rpx;
	}

	.payPrice {
		font-size: 70rpx;
		color: #000;
		height: 120rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.payPrice text {
		font-size: 28rpx;
	}

	.payTime {
		font-size: 24rpx;
		color: #999;
		line-height: 56rpx;
		text-align: center;
	}
</style>